function addItemToOrder(itemName, itemID, foodCodes){
    //set the date
    var d = new Date();
    var theDate = d.getFullYear() + '-' + (d.getMonth()+1) + '-' + d.getDate();
    //get the global item count to use for IDs and add one to it
    var globalCount = parseInt(document.getElementById('globItems').innerHTML);
    globalCount = globalCount + 1;
    document.getElementById('globItems').innerHTML = globalCount;
    //get the number of items in the order and add one to it
    var itemCount = parseInt(document.getElementById('numItems').innerHTML);
    itemCount = itemCount + 1;
    document.getElementById('numItems').innerHTML = itemCount;
    
    var orderList = document.getElementById('orderDiv');
    var orderListContent = orderList.innerHTML;
    orderListContent = orderListContent + '<div id=\'item_'+globalCount+'\'><div class=\'itemDiv\'>Item ' + globalCount + ': ' + itemName
                        + '<input type=\'hidden\' name=\'item_'+globalCount+'\'value=\''+itemID+'_'+foodCodes+'_'+theDate+'\' /></div>'
                        + '<div class=\'removeButtonDIV\'><form method=\'LINK\' action=\'javascript:removeItem('+globalCount+')\'><input type=\'submit\' value=\'Remove Item\' /></form></div>'
                        + '</div>';

    orderList.innerHTML = orderListContent;

}

function removeItem(item){
    var itemDiv = document.getElementById('item_'+item);
    itemDiv.parentNode.removeChild(itemDiv);
    var newItemCount = parseInt(document.getElementById('numItems').innerHTML);
    newItemCount = newItemCount -1;
    document.getElementById('numItems').innerHTML = newItemCount;
    if(newItemCount == 0){
        document.getElementById('globItems').innerHTML = 0;
    }
}

function checkOrders(){
    var itemCount = parseInt(document.getElementById('numItems').innerHTML);
    
    if(itemCount == 0){
        alert('Order contains 0 items.\n\nPlease add item(s) to the order before submitting.');
        return false;
    }
    else{
        return true;
    }
}
